import * as mongoose from 'mongoose';
/**http模型 */
export const HttpLogModel = new mongoose.Schema({
	trackId:{
		type:String,
        default:""
	},
	ip:{
		type:String,
        default:""
	},
	user: {
		type:String,
        default:""
	},
	url:{
		type:String,
        default:""
	},
	method:{
		type:String,
        default:""
	},
	timeMs:{
		type:Number,
        default:0
	},
	headers:{
		type:Object,
		default:{}
	},
	params:{
		type:Object,
		default:{}
	},
	body:{
		type:Object,
		default:{}
	},
	responseFrom:{
		type:String,
        default:""
	},
    responseCode:{
        type:Number,
        default:0
    },
    responseData:{
        type:Object,
    },
	error:{
		type:Object,
		default:{}
	}
},{
    timestamps: {
        createdAt: 'createdAt',
        updatedAt: 'updatedAt'
    },
	shardKey:{
		_id:"hashed"
	}
});

HttpLogModel.index({ createdAt: 1,timeMs:-1,method:1,trackId:1 }, { expireAfterSeconds: 604800 });

export interface HttpLog extends Document {
	readonly _id: string;
	/**trackId */
	readonly trackId:string,
	/**ip */
	readonly ip:string,
	/**所属用户 */
	readonly user: string;
	/**请求路径 */
	readonly url: string;
	/**请求方法 */
	readonly method: string;
	/**请求耗时 */
	readonly timeMs: number;
	/**请求头参数 */
	readonly headers: any;
	/**请求路径参数 */
	readonly params: any;
	/**请求体参数 */
	readonly body: any;
	/**响应来源 */
	readonly responseFrom:string,
	/**响应码 */
	readonly responseCode: any;
	/**响应内容 */
	readonly responseData: any;
	/**错误信息 */
	readonly error: any;
}
